/**************************************************************************************
* Component of simpleRTJ regression tests.
**************************************************************************************
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL RTJ COMPUTING BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Created by:
*       RTJ Computing
**************************************************************************************/
public class TestFinally
{
    public boolean doFinally (boolean b)
    {
        boolean rv;
        try
        {
            if (b)
            {
                throw new Exception ();
            }
            else
            {
                rv = false;
            }
        }
        catch (Exception e)
        {
            rv = false;
        }
        finally
        {
            rv = true;
        }
        return rv;
    }

    public boolean doFinallyNested (boolean b)
    {
        boolean rv;
        try
        {
            try
            {
                if (b)
                {
                    throw new Exception ();
                }
                else
                {
                    rv = false;
                }
            }
            catch (Exception e)
            {
                rv = false;
            }
            finally
            {
                rv = true;
            }
        }
        finally
        {
            if (b)
                rv = true;
            else
                rv = false;
        }
        return rv;
    }

    public static void test() throws Exception
    {
        TestFinally tf = new TestFinally ();

        if (!tf.doFinally (true)) throw new Exception("FIN1");
        if (!tf.doFinally (false)) throw new Exception("FIN2");
        if (!tf.doFinallyNested (true)) throw new Exception("FIN3");
        if (tf.doFinallyNested (false)) throw new Exception("FIN4");
    }
}
